package com.zegome.game.gomestory.main.scene.play.board;

import aurelienribon.tweenengine.BaseTween;
import aurelienribon.tweenengine.Tween;
import aurelienribon.tweenengine.TweenCallback;
import aurelienribon.tweenengine.equations.Quad;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.zegome.game.gomestory.main.A;
import com.zegome.game.gomestory.main.G;
import com.zegome.game.gomestory.main.helper.StageHelper;
import com.zegome.game.util.helper.WidgetAccessor;

public class AniGift {
	
	Board board;
	
	private Image black;	
	Label label;
	private Image gift;
	
	public AniGift(Board board){
		this.board = board;
	}
	
	public void in(){
		if(black==null){
			black = board.screen.ctr.stageHelper.createImage(board.screen.ctr.a.transRegion, 0, 0, (80), (300));
		}
		if(gift==null){
			gift = board.screen.ctr.stageHelper.createImage(board.screen.ctr.a.iconRegion[0][0], 0, 0, (58), (58));
		}
		if(label==null){
			label = board.screen.ctr.stageHelper.createLabel(board.screen.ctr.g.mFont, "Nhanh tay sưu tầm", Color.WHITE, (0), (0));
		}
				
		black.remove();
		label.remove();
		gift.remove();
		
		board.screen.getStage().addActor(black);
		board.screen.getStage().addActor(label);
		board.screen.getStage().addActor(gift);
		
		label.setVisible(false);
		label.setColor(1f, 1f, 1f, 0.0f);
		gift.setColor(1f, 1f, 1f, 0.0f);
		gift.setVisible(false);
		black.setVisible(true);
		Color color = black.getColor();
		color.set(0.1f, 0.1f, 0.1f, 0.0f);
		color.a = 0.9f;
		black.setColor(color);
				
		Tween.to(black, WidgetAccessor.SCALE_XY, 1f).target(5f,1f).ease(Quad.OUT)
		.setCallback(new TweenCallback() {			
			@Override
			public void onEvent (int arg0, BaseTween<?> arg1) {
				// TODO Auto-generated method stub
				gift.setVisible(true);
				label.setVisible(true);
				Tween.to(label, WidgetAccessor.OPACITY, 1f).target(1f).ease(Quad.OUT).start(board.screen.getTween());
				Tween.to(gift, WidgetAccessor.OPACITY, 1f).target(1f).ease(Quad.OUT).start(board.screen.getTween());
			}
		})
		.start(board.screen.getTween());
	}
	
	public void out(){
		if(black==null){
			black = board.screen.ctr.stageHelper.createImage(board.screen.ctr.a.transRegion, 0, 0, (800), (800));
		}
		if(label==null){
			label = board.screen.ctr.stageHelper.createLabel(board.screen.ctr.g.mFont, "Nhanh tay sưu tầm", Color.WHITE, (100), (200));
		}
				
		black.remove();
		label.remove();
		board.screen.getStage().addActor(black);
		board.screen.getStage().addActor(label);
		black.setVisible(true);
		Color color = black.getColor();
		color.set(0.1f, 0.1f, 0.1f, 0.0f);
		color.a = 0.8f;
		black.setColor(color);
		
		Tween.to(black, WidgetAccessor.OPACITY, 1f).target(0.0f).ease(Quad.OUT)
		.setCallback(new TweenCallback() {
			
			@Override
			public void onEvent (int arg0, BaseTween<?> arg1) {
				// TODO Auto-generated method stub
				
			}
		})
		.start(board.screen.getTween());
		Tween.to(label, WidgetAccessor.OPACITY, 0.4f).target(0.0f).ease(Quad.OUT)
		.start(board.screen.getTween());
	}
	
}
